function [y, delta] = polyval(p,x) //%POLYVAL Evaluate polynomial. //% Y = POLYVAL(P,X), when P is a vector of length N+1 whose elements //% are the coefficients of a polynomial, is the value of the //% polynomial evaluated at X. //% //% Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1) //% //% If X is a matrix or vector, the polynomial is evaluated at all //% points in X. See also POLYVALM for evaluation in a matrix sense. //% //% See also POLYFIT. [m,n] = size(x); nc = length(p); //% Use Horner's method for general case where X is an array. y = zeros(m,n); if length(p)>0, y(:) = p(1); end for i=2:nc y = x .* y + p(i); end